package com.jd.jdnlp;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringEscapeUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLDecoder;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by liteng5 on 2016/11/3.
 */
public class AnalyzeServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request,HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String acticle = request.getParameter("acticle");
        System.out.println(acticle);
        acticle = StringEscapeUtils.unescapeHtml4(acticle);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(acticle.getBytes());
        Reader reader = new InputStreamReader(byteArrayInputStream);
        response.setContentType("text/html;charset=UTF-8");
        Map<String,Double> topicMap = Analyzer.doAnalyze(reader,Analyzer.TOMODLE);
        PrintWriter out = response.getWriter();
        out.print(JSONObject.toJSON(topicMap));
    }

}
